//
//  DownloadVideoManager.h
//  MVideo
//
//  Created by Lin Eidan on 14-4-1.
//  Copyright (c) 2014年 taomee. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "M3U8Handle.h"
#import "M3U8DownloadManage.h"
@class VideoObj;

@protocol DownloadVideoManagerDelegate;



#define VideoType                 @"videoType"
#define VideoTypeM3U8             @"m3u8"
#define VideoTypeNormal           @"mp4"
#define MinFreeDiskSpace          0.2                         //单位是G，即100M,小于这个数，提示空间不足
#define MaxDownladNum             100

@interface DownloadVideoManager : NSObject<M3U8HandleDelegate,M3U8DownloadManageDelegate>

@property (strong, nonatomic) NSMutableArray *downloadQueue;
@property (strong, nonatomic) NSMutableArray *successQueue;
@property (weak, nonatomic) id<DownloadVideoManagerDelegate>delegate;


+ (DownloadVideoManager *)sharedInstance;

-(void)addTheVideoToDownloadQueueWith:(VideoObj *)downVideoObj;

-(void)startDownload;

-(void)startDownloadTheVideoWithObj:(VideoObj *)obj;

-(BOOL)isHasObjInLoading;

-(void)downloadCellHasClicked:(int )index;

-(void)downloadCellHasClickedWithObj:(VideoObj *)obj;

-(void)removeAllDownloadRequest;

-(void)deleteTheDownloadItemsWithRemoveArray:(NSArray *)removeArray andIsDownloading:(BOOL)isDownloading;

-(void)deleteTheDownloadSuccessContentIdDetailItemsWithId:(NSString *)detailId andRemoveArray:(NSArray *)removeArray;

-(void)deleteFileWithObj:(VideoObj *)obj;

-(BOOL)findTheEpisodeIsInSuccessQueueWithContentId:(NSString *)contentId andEpisodeId:(NSString *)episodeId andIsNeedToFindInDowningQueue:(BOOL)isNeedFindInDowingQueue;

-(VideoObj *)getTheObjFromSuccessQueueWithContentId:(NSString *)contentId andEpisodeId:(NSString *)episodeId;

//下载，没网络观看的时候，需要创建一个假的播放列表。
-(NSMutableArray *)createLocalPlayListArrayWithObj:(VideoObj *)obj;

-(NSString *)getEpisodeFilePathWithContentId:(NSString *)contentId andEpisodeId:(NSString *)episodeId andNeedCreateFolder:(BOOL)isNeed;

-(NSString *)getLocalServerRequestFolderPathWithContentId:(NSString *)contentId andEpisodeId:(NSString *)episodeId;

-(void)backgrondDownloadOneTaskComplete;

-(void)saveQueueToLocal;

//后台
-(void)handleTheLastTerminate;

@end

@protocol DownloadVideoManagerDelegate <NSObject>

@optional

//开始下载回调
-(void)updateStartDownLoadUIInTheItemWithIndex:(int )index;

//下载失败回调
-(void)updateFailedUIInTheItemWithIndex:(int )index;

//public 更新百分比
-(void)updateHasDownloadPer:(float)per inTheItemWithIndex:(int )index;

//下载成功回调
-(void)updateSuccessUIInTheItemWithIndex:(int )index;

-(void)updateListViewUI;

@end
